package com.sky.Task;

import com.sky.entity.Orders;
import com.sky.mapper.OrderMapper;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import java.time.LocalDateTime;

@Component
@Slf4j
public class OrderTask {
    @Autowired
    private OrderMapper orderMapper;
    @Value("${orderTimeOut}")
    private long ORDER_TIMEOUT_MINUTE = 15;//超时时间

    private int count = 0;

    /**
     * 处理超时订单
     */
    @Scheduled(cron = "0/2 * * * * ? ")
    public void processTimeoutOrder(){
        // TODO 处理超时订单--------------------------------------------------------------------
////        log.info("处理超时订单{}", LocalDateTime.now());
//        if(this.count == 100){
//            System.out.println("~");
//            //傻逼被骗了吧哈哈哈啊
////            log.error("程序出现了BUG请及时修复!!{}", LocalDateTime.now());
//            this.count = 0;
//        }else {
////            System.out.print("\uD83E\uDD14");
//            if(this.count == 0){
//                System.err.println("我先睡会等会服务^ v ^:");
//            }
//            System.out.print("z");
//            this.count++;
//        }
        //-------------------------------------------------------------------------------------
        orderMapper.updateStatusByTime(Orders.PENDING_PAYMENT, LocalDateTime.now().minusMinutes(ORDER_TIMEOUT_MINUTE),"用户未支付!订单超时!");
    }
    /**
     * 处理一直在拍送中的订单
     */
    @Scheduled(cron = "0 0 1 * * ? ")
    public void deliveryOrder(){
        log.info("处理一直在拍送中的订单订单{}", LocalDateTime.now());
        orderMapper.deliveryOrder(Orders.DELIVERY_IN_PROGRESS);
    }
}
